﻿using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebServerConnectorDll;

namespace FridgeManagerApp
{
    class DominoTypeInsertViewModel : NotificationObject
    {
        DominoTypeInsert gWindow;
        DominoTypeViewModel gParentViewModel;

        public DominoTypeInsertViewModel(DominoTypeInsert pWindow, DominoTypeViewModel pParentViewModel)
        {
            gWindow = pWindow;
            gParentViewModel = pParentViewModel;
        }

        private String dominoTypeName;
        public String DominoTypeName
        {
            get
            {
                return dominoTypeName;
            }
            set
            {
                dominoTypeName = value;
                RaisePropertyChanged("DominoTypeName");
            }
        }

        private String dominoImage;
        public String DominoImage
        {
            get
            {
                return dominoImage;
            }
            set
            {
                dominoImage = value;
                RaisePropertyChanged("DominoImage");
            }
        }

        private String dominoVolume;
        public String DominoVolume
        {
            get
            {
                return dominoVolume;
            }
            set
            {
                dominoVolume = value;
                RaisePropertyChanged("DominoVolume");
            }
        }

        private String company;
        public String Company
        {
            get
            {
                return company;
            }
            set
            {
                company = value;
                RaisePropertyChanged("Company");
            }
        }

        private String hasee;
        public String Hasee
        {
            get
            {
                return hasee;
            }
            set
            {
                hasee = value;
                RaisePropertyChanged("Hasee");
            }
        }
        protected DelegateCommand<object> insertCommand;
        public DelegateCommand<object> InsertCommand
        {
            get
            {
                return insertCommand ?? (insertCommand = new DelegateCommand<object>(AInsertCommand, BInsertCommand));
            }
        }

        protected virtual void AInsertCommand(object obj)
        {
            List<WDominoType> list = new List<WDominoType>();
            WDominoType item = new WDominoType();
            item.DominoTypeName = DominoTypeName;
            item.DominoImage = DominoImage;
            item.DominoVolume = DominoVolume;
            item.Company = Company;
            item.Hasee = Hasee;
            list.Add(item);
            HttpResponse response = WDominoType.Insert(list);

            gWindow.Close();
            gParentViewModel.UpdateList();
        }

        private bool BInsertCommand(object arg)
        {
            return true;
        }

        protected DelegateCommand<object> quitCommand;
        public DelegateCommand<object> QuitCommand
        {
            get
            {
                return quitCommand ?? (quitCommand = new DelegateCommand<object>(AQuitCommand, BQuitCommand));
            }
        }

        protected virtual void AQuitCommand(object obj)
        {
            gWindow.Close();
            gParentViewModel.UpdateList();
        }

        private bool BQuitCommand(object arg)
        {
            return true;
        }
    }
}
